package com.me.batm.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.me.batm.GameConstants;
import com.me.batm.OurGdxGame;

public class TestScreen implements Screen{
	BitmapFont font;
	SpriteBatch spriteBatch;
	OurGdxGame ourGdxGame;
	
	Sound sound;	
	float timer;
	long soundId;
	
	public TestScreen(OurGdxGame ourGdxGame){
		this.ourGdxGame = ourGdxGame;
		timer = 0f;
		playSound = false;
	}
	boolean playSound;
	
	@Override
	public void render(float delta) {
		//Gdx.gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
		Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		
		timer += delta;
		
		spriteBatch.begin();
			font.draw(spriteBatch, "Testing your Sound System", GameConstants.SCREEN_WIDTH*0.4f, GameConstants.SCREEN_HEIGHT*0.5f);
			if(timer >= 2f && timer <= 7f){
				font.draw(spriteBatch, "Left", GameConstants.SCREEN_WIDTH*0.3f, GameConstants.SCREEN_HEIGHT*0.3f);
				if(playSound == false){
					soundId = sound.play();
					sound.setLooping(soundId, true);
					sound.setPan(soundId, -1f, 1f);
					playSound = true;
				}
			}			
			if(timer >= 7.1f && timer <= 12f){
				if(playSound == true){
					playSound = false;
					sound.setPan(soundId, 1f, 1f);
				}
				font.draw(spriteBatch, "Right", GameConstants.SCREEN_WIDTH*0.6f, GameConstants.SCREEN_HEIGHT*0.3f);
			}
			if(timer >= 12f){
				sound.stop();
				ourGdxGame.setScreen(new MainScreen(ourGdxGame, ""));
			}
		spriteBatch.end();
	}

	@Override
	public void resize(int width, int height) {
	}

	@Override
	public void show() {
		font = new BitmapFont();
		spriteBatch = new SpriteBatch();
		sound = Gdx.audio.newSound(Gdx.files.internal("latidomono.wav"));

		spriteBatch
		.getProjectionMatrix()
		.setToOrtho2D(0,0,GameConstants.SCREEN_WIDTH, GameConstants.SCREEN_HEIGHT);
	}

	@Override
	public void hide() {	
	}

	@Override
	public void pause() {
	}

	@Override
	public void resume() {
	}

	@Override
	public void dispose() {	
	}
}
